/**
 * Author: <NAME>
 * Created: August 10, 2021
 * 
 * This is a simple program to demonstrate the basic data types in Rust.
 */

fn main() {
    let x:u8 = 255;
    let y:i8 = -128;
    let z:i16 = -32768;
    let w:i32 = -2147483648;
    let v:i64 = -9223372036854775808;
    println!("x = {}, y = {}, z = {}, w = {}, v = {}", x, y, z, w, v);

    let a:f32 = 3.1415926;
    let b:f64 = 2.71828182845904523536028747135266249775724709369995;
    println!("a = {}, b = {}", a, b);

    let tup: (i32, f64, bool) = (10, 3.14, true); // tuple
    println!("tup = {:?}", tup);
    let (xx, yy, zz) = tup; // destructuring
    println!("xx = {}, yy = {}, zz = {}", xx, yy, zz);

    println!("xxx = {}, yyy = {}, zzz = {}", tup.0, tup.1, tup.2); // accessing tuple elements by index

    // array
    let a = [1, 2, 3, 4, 5]; // array
    println!("a = {:?}", a);
    let b = [0; 5]; // array with all elements initialized to 0
    println!("b = {:?}", b);
    let c:[i32; 5] = [1, 2, 3, 4, 5]; // fixed size array
    println!("c = {:?}", c);
    for i in c {
        println!("{}", i);
    }
    for i in 0..5 {
        println!("---{}", c[i]);
    }

    // function
    let result = add(10, 20);
    println!("result = {}", result);

    // let result = add(3.14, 2.0); // error: mismatched types
    // println!("result = {}", result);
}

fn add(x:i32, y:i32) -> i32 {
    x + y
    // return x + y; 
}

// fn add(x:f32, y:f32) -> f32 { // rust no overloading
//     x + y
// }